package com.xiao.sulinges.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: 1322127758@qq.com
 * @date: 2022/3/20 10:21
 * @作用:
 */
@Configuration
public class ElasticSearchConfig {
    /**
     * 对es操作需要用的一个常用数据
     */
    public static final RequestOptions COMMON_OPTIONS;
    static{
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();

        COMMON_OPTIONS = builder.build();
    }

    /**
     * 连接Es配置
     * @return
     */
    @Bean
    public RestHighLevelClient esConfig(){
        RestClientBuilder builder = null;
        /**
         * " 192.168.0.101是es的主机地址， 9200 是端口， 参数三是：访问的方式
         */
        builder = RestClient.builder(new HttpHost("192.168.0.101",9200,"http"));
//        builder = RestClient.builder(new HttpHost("127.0.0.1",9200,"http"));
        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(builder);
        return restHighLevelClient;
    }

}
